package com.popwindow;

import android.annotation.SuppressLint;
import android.graphics.drawable.ColorDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by bichuanfeng on 2017/2/16.
 */

public class PopWindowUtil {
    public static Popwindows getPopupWindow(View root) {

        return getPopupWindow(root, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    public static Popwindows getPopupWindow(View root, int width, int height) {
        final Popwindows popup = new Popwindows(root, width, height);
        popup.setTouchable(true); // 设置popupwindow可点击
        popup.setOutsideTouchable(true); // 设置popupwindow外部可点击
        popup.setFocusable(true); // 获取焦点
        ColorDrawable cd = new ColorDrawable(0x00000000); // 设置背景 0x00000000
        popup.setBackgroundDrawable(cd);
        popup.setTouchInterceptor(new View.OnTouchListener() {
            @SuppressLint("ClickableViewAccessibility")
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                    popup.dismiss();
                    return true;
                }
                return false;
            }
        });
        return popup;
    }
}
